﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Media;

namespace Hi_Baidu.MusicPlayer
{
    /// <summary>
    ///     提供了播放声音的相关操作
    /// </summary>
    public class MusicPlayer
    {
        private static String PLAY_PATH = "";
         /// <summary>
        ///     使用默认声音提示
        /// </summary>
        /// <param name="songType">播放歌曲的类别</param>
        public static void Play(SongType songType)
        {
            switch (songType)
	        {
		        case SongType.ONLINE:
                    PLAY_PATH = "../Misc/Sound/Classic/Global.wav";
                    Play();
                 break;
                case SongType.OFFLINE:
                 break;
                case SongType.SYSTEM_MESSAGE:
                    PLAY_PATH = "../Misc/Sound/Classic/system.wav";
                    Play();
                 break;
                case SongType.NORMAL_TALK:
                 break;
                case SongType.VOICE_TALK:
                 break;
                case SongType.VIDEO_TALK:
                 break;
                case SongType.WINDOW_SHADOW:
                    PLAY_PATH = "../Misc/Sound/Classic/shake.wav";
                     Play();
                 break;
                default:
                 break;
	        }
        }

        /// <summary>
        ///     播放歌曲的类别
        /// </summary>
        public enum SongType
        {
            /// <summary>
            ///     上线声音 
            /// </summary>
            ONLINE,
            /// <summary>
            ///     下线声音
            /// </summary>
            OFFLINE,
            /// <summary>
            ///     系统消息声音
            /// </summary>
            SYSTEM_MESSAGE,
            /// <summary>
            ///     普通文字聊天声音 
            /// </summary>
            NORMAL_TALK,
            /// <summary>
            ///     语音聊天声音
            /// </summary>
            VOICE_TALK,
            /// <summary>
            ///     视频聊天声音
            /// </summary>
            VIDEO_TALK,
            /// <summary>
            ///     窗口抖动
            /// </summary>
            WINDOW_SHADOW
        }

        /// <summary>
        ///     内部方法- 使用多线程播放指定音乐文件
        /// </summary>
        private static void Play()
        {
            Thread thread = new Thread(new ThreadStart(INNER_Play));
            thread.Name = "The thread of play sound";
            thread.Start();
        }

        /// <summary>
        ///     播放指定音乐文件
        /// </summary>
        private static void INNER_Play()
        {
            using(SoundPlayer soundPlayer = new SoundPlayer())
            {
                soundPlayer.SoundLocation = PLAY_PATH;
                soundPlayer.Play();
            }
        }
    }
}